package org.jiuling.aliyun.sms.factory.impl;

import org.jiuling.aliyun.config.exception.AliYunConfigRuntimeException;
import org.jiuling.aliyun.sms.config.AliYunSmsConfig;
import org.jiuling.aliyun.sms.enums.PatternEnum;
import org.jiuling.aliyun.sms.factory.AliYunSmsFactory;
import org.jiuling.aliyun.sms.factory.service.*;
import org.jiuling.aliyun.sms.factory.service.impl.*;

/**
 * 阿里云工厂实现类
 * @author 紫灵
 * @date 2023年03月02日 00时55分07秒
 */
public class AliYunSmsFactoryImpl implements AliYunSmsFactory {

    /** 调用模式 */
    private final PatternEnum pattern;
    private final AliYunSmsConfig aliYunSmsConfig;
    private final String EXCEPTION_MESSAGE = "未知调用方式！";

    public AliYunSmsFactoryImpl(PatternEnum pattern, AliYunSmsConfig aliYunSmsConfig) {
        this.pattern = pattern;
        this.aliYunSmsConfig = aliYunSmsConfig;
    }

    @Override
    public AliYunSendSmsQueryService aliYunSendSmsQueryService() {
        switch (pattern){
            case ASYNCHRONOUS:
                return new AliYunAsyncSendSmsQueryServiceImpl(aliYunSmsConfig);
            case SYNCHRONIZATION:
                return new AliYunSyncSendSmsQueryServiceImpl(aliYunSmsConfig);
            default:
                throw new AliYunConfigRuntimeException(EXCEPTION_MESSAGE);
        }
    }

    @Override
    public AliYunSendSmsService aliYunSendSmsService() {
        switch (pattern){
            case ASYNCHRONOUS:
                return new AliYunAsyncSendSmsServiceImpl(aliYunSmsConfig);
            case SYNCHRONIZATION:
                return new AliYunSyncSendSmsServiceImpl(aliYunSmsConfig);
            default:
                throw new AliYunConfigRuntimeException(EXCEPTION_MESSAGE);
        }
    }

    @Override
    public AliYunShortChainManagementService aliYunShortChainManagementService() {
        switch (pattern){
            case ASYNCHRONOUS:
                return new AliYunAsyncShortChainManagementServiceImpl(aliYunSmsConfig);
            case SYNCHRONIZATION:
                return new AliYunSyncShortChainManagementServiceImpl(aliYunSmsConfig);
            default:
                throw new AliYunConfigRuntimeException(EXCEPTION_MESSAGE);
        }
    }

    @Override
    public AliYunSignatureManagementService aliYunSignatureManagementService() {
        switch (pattern){
            case ASYNCHRONOUS:
                return new AliYunAsyncSignatureManagementServiceImpl(aliYunSmsConfig);
            case SYNCHRONIZATION:
                return new AliYunSyncSignatureManagementServiceImpl(aliYunSmsConfig);
            default:
                throw new AliYunConfigRuntimeException(EXCEPTION_MESSAGE);
        }
    }

    @Override
    public AliYunTemplateManagerService aliYunTemplateManagerService() {
        switch (pattern){
            case ASYNCHRONOUS:
                return new AliYunAsyncTemplateManagerServiceImpl(aliYunSmsConfig);
            case SYNCHRONIZATION:
                return new AliYunSyncTemplateManagerServiceImpl(aliYunSmsConfig);
            default:
                throw new AliYunConfigRuntimeException(EXCEPTION_MESSAGE);
        }
    }
}
